package com.rd.student.ruanjian.class4.lichunquan.Text02;

import java.util.ArrayList;
import java.util.Collections;

public class Test09 {
    //16个国家分四组进行球赛
    public static void main(String[] args) {
        ArrayList<String> arrayList_name = new ArrayList<>();//长度为16，四个国家
        ArrayList<ArrayList<String>> arrayList_cls = new ArrayList<>();//长度为4，四组
        ArrayList<String> arrayList = new ArrayList<>();
        String str = "科特迪瓦,阿根廷,澳大利亚,塞尔维亚,荷兰,尼日利亚,日本,美国,中国,新西兰,巴西,比利时,韩国,喀麦隆,洪都拉斯,意大利";
        //截取
        String[] str01 = str.split(",");
        //添加到arrayList_name集合
        Collections.addAll(arrayList_name, str01);
        //将集合中的元素打乱
        Collections.shuffle(arrayList_name);
        //分组
        for (int i = 0 , j = 0; i < arrayList_name.size();) {
            while(j < 4){
                arrayList.add(arrayList_name.get(i));
                j++;
                i++;
            }
            arrayList_cls.add(arrayList);
            arrayList = new ArrayList<String>();
            j=0;
        }
        //查看分组结果
        for (int i = 0; i < arrayList_cls.size(); i++) {
            ArrayList<String> arrayList1 = arrayList_cls.get(i);
            System.out.println("---------");
            for (int j = 0; j < 4; j++) {
                System.out.println(arrayList1.get(j));
            }
            System.out.println("----------");
        }
    }
}
